#include "AccountServer.h"
#include "JME_Core.h"
#include "JME_JsonFile.h"
#include "JME_RpcHandler.h"
#include "AccountHandler.h"

void AccountServer::init()
{
	_config = JMEngine::file::load_jsonfile_val("./config/conf.json");
	auto& _baseConf = _config["base"];

	_serverId = _baseConf["server_id"].asInt();

	_dbPool = MysqlDBPool::create(4, boost::bind(connectMysql, _1, "127.0.0.1", "username", "pwd", "dbname", 3306));
	
	JME_RpcHandler::bindHandler<AccountRpcHandler>();

	auto& rpc = _config["rpc"];
	auto& serverConf = rpc["server"];

	_rpcServer = JME_RpcServer::create(JME_RpcHandler::create(), serverConf["port"].asUInt(), serverConf["buffer_size"].asUInt());
}

AccountServer::AccountServer()
{
	
}

AccountServer::AccountServerPtr AccountServer::getInstance()
{
	static AccountServerPtr _pInstance = AccountServerPtr(new AccountServer);
	return _pInstance;
}


MysqlDBPool* AccountServer::getDBPool()
{
	return _dbPool.get();
}

AccountServer::~AccountServer()
{

}

